/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javiermoreno.bankof.dominio.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author Administrador
 */
class ConexionFactory {

//    public static final String URL = 
//            "jdbc:derby:c:/temp/datosbankof";
//    
//    static 
//    {
//        try {
//            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//        } catch (ClassNotFoundException ex) {
//            ex.printStackTrace();
//        }
//    }
//    
//    static Connection crear() throws SQLException {        
//        Connection resultado =
//                DriverManager.getConnection(URL);
//        
//        return resultado;
//        
//    }
    
    
    static Connection crear() throws SQLException {
        try {
            Context initContext = new InitialContext();
            Context envContext  = (Context)initContext.lookup("java:/comp/env");
            DataSource ds = (DataSource)envContext.lookup("jdbc/bankofds");
            Connection conn = ds.getConnection();        
            return conn;
        } catch (NamingException ex) {
            ex.printStackTrace();
            SQLException sqlExc = new SQLException(ex);
            throw sqlExc;
        }
        
    }
    
}
